//************************************************************
//  LinearNode.java       Authors: Lewis/Chase
//
//  Represents a node in a linked list.
//************************************************************

package jss2;

public class LinearNode <T> {

	private T				element;

	private LinearNode <T>	next;

	//---------------------------------------------------------
	//  Creates an empty node.
	//---------------------------------------------------------
	public LinearNode () {

		this.next = null;
		this.element = null;
	}

	//---------------------------------------------------------
	//  Creates a node storing the specified element.
	//---------------------------------------------------------
	public LinearNode (final T elem) {

		this.next = null;
		this.element = elem;
	}

	//---------------------------------------------------------
	//  Returns the element stored in this node.
	//---------------------------------------------------------
	public T getElement () {

		return this.element;
	}

	//---------------------------------------------------------
	//  Returns the node that follows this one.
	//---------------------------------------------------------
	public LinearNode <T> getNext () {

		return this.next;
	}

	//---------------------------------------------------------
	//  Sets the element stored in this node.
	//---------------------------------------------------------
	public void setElement (final T elem) {

		this.element = elem;
	}

	//---------------------------------------------------------
	//  Sets the node that follows this one.
	//---------------------------------------------------------
	public void setNext (final LinearNode <T> node) {

		this.next = node;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString () {

		// prints the entire list:
		//return String.format ("LinearNode [element=%s, next=%s]", this.element, this.next);

		return String.format ("%s [element=%s]", this.getClass ().getName (),
				this.element);
	}

}
